<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input
        class="filter-item"
        placeholder="手机号搜索"
        v-model="listQuery.keyword"
        style="width: 20%"
      >
      </el-input>

      <el-input
          class="filter-item"
          placeholder="设备搜索"
          v-model="listQuery.sn"
          style="width: 16%;margin-left:10px"
      >
      </el-input>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="getList"
                 style="margin-left: 10px"
      >
        搜索
      </el-button>
    </div>
    <el-table v-loading="listLoading" :data="list" border fit highlight-current-row style="width: 100%">
      <el-table-column align="center" label="ID" min-width="80">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column min-width="80" align="center" label="设备号">
        <template slot-scope="scope">
          <span>{{ scope.row.sn }}</span>
          <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
        </template>
      </el-table-column>
      <el-table-column min-width="80" align="center" label="蓝牙id">
        <template slot-scope="scope">
          <span>{{ scope.row.name }}</span>
          <!--          <span>{{ scope.row.timestamp | parseTime('{y}-{m}-{d} {h}:{i}') }}</span>-->
        </template>
      </el-table-column>
      <el-table-column min-width="80" align="center" label="校表">
        <template slot-scope="scope">
          <span v-if="scope.row.step_2">是</span>
          <span v-else>否</span>
        </template>
      </el-table-column>
      <el-table-column min-width="80" align="center" label="开/合闸">
        <template slot-scope="scope">
          <span v-if="scope.row.step_3">是</span>
          <span v-else>否</span>
        </template>
      </el-table-column>
      <el-table-column min-width="80" align="center" label="清表">
        <template slot-scope="scope">
          <span v-if="scope.row.step_4">是</span>
          <span v-else>否</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80" align="center" label="精度误差">
        <template slot-scope="scope">
          <span>{{scope.row.error_ratio}}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80" align="center" label="设备类型">
        <template slot-scope="scope">
          <span v-if="scope.row.device_type == 1">4G</span>
          <span v-else>蓝牙</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80" align="center" label="mac">
        <template slot-scope="scope">
          <span>{{scope.row.mac}}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="80" align="center" label="代理手机号">
        <template slot-scope="scope">
          <span>{{scope.row.mobile}}</span>
        </template>
      </el-table-column>

      <el-table-column min-width="120" align="center" label="过载电流">
        <template slot-scope="scope">
          <span>{{ scope.row.overload_i }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" min-width="180">
        <template slot-scope="scope">
          <el-button type="danger" size="small" icon="el-icon-delete" circle @click="del(scope.row.id)">
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
                @pagination="getList"
    />

  </div>
</template>

<script>
import { getList, del} from '@/api/record'
import { all } from '@/api/role'
// import { getMenus } from '@/api/menu'
import Pagination from '@/components/Pagination'
import store from '@/store'
import router from '@/router' // Secondary package based on el-pagination
import ImageCropper from '@/components/ImageCropper'
import PanThumb from '@/components/PanThumb'

export default {
  name: 'TestRecord',
  components: { Pagination, ImageCropper, PanThumb },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      menus: [],
      roles: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        keyword: '',
        sn:''
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      filterText: '',
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      countTemp:{
        id:undefined,
        call_count:0,
        call_count_used:0,
        api_url:'',
        call_count_used_month:0,
        token:''
      },
      drawer:false,
      now_title:'',
      rules: {
        name: [{ required: true, message: '昵称不能为空', trigger: 'blur' }],
        roles_id: [{ required: true, message: '请选择身份', trigger: 'blur' }],
        email: [{ required: true, message: '请填写账号', trigger: 'blur' }],
        // password: [{ required: true, message: '请输入密码', trigger: 'blur' }]
      }
    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.getList()
  },
  methods: {

    getList() {
      this.listLoading = true
      getList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    del(id) {
      this.$confirm('确认要删除该条数据吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        del(id).then(response => {
          this.getList()
          if (response.data.code == 200) {
            this.$notify.success({
              title: '成功',
              message: response.msg,
              type: 'success',
              duration: 2000
            })
          } else {
            this.$notify.error({
              title: '失败',
              message: response.data.msg,
              duration: 2000
            })
          }
        })
      }).catch(() => {

      })
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}

.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
<style scoped>
.avatar {
  width: 200px;
  height: 200px;
  border-radius: 50%;
}
</style>
